;
(function() {
	'use strict';
	angular.module('services.resourcesWatchData.allInfoDisplay')
		.factory('allInfoDisplayService', allInfoDisplayService);

	function allInfoDisplayService(Restangular) {
		return {
			queryHostNum: queryHostNum,
			queryHostInfo: queryHostInfo,
			getRegion: getRegion,
			getHostInfo: getHostInfo,
			getfmtSend: getfmtSend
		};

		function getfmtSend(sendData, regions) {
			var send = {
				systemCode: sendData.systemCode,
				regionCode: []
			};
			if (sendData.regionCode.length === 0) {
				angular.forEach(regions, function(rg) {
					send.regionCode.push(rg.regionCode);
				});
			} else {
				send.regionCode = sendData.regionCode.map(function(data) {
					return data.regionCode;
				});
			}
			return send;
		}

		function queryHostNum(params, callback) {
			Restangular.all('sas/resourceMonitoring/hostMessage/hostWholeInfo').post(params).then(callback);
		}

		function queryHostInfo(params, callback) {
			Restangular.all('sas/resourceMonitoring/hostMessage/hostWholeDetail').post(params).then(callback);
		}

		function getRegion(params, callback) {
			Restangular.all('sas/resourceMonitoring/hostMessage/getRegion').post(params).then(callback);
		}

		function getHostInfo(res, info, title, yName) {
			var temp = {
				echartsX: [],
				rate: []
			};
			angular.forEach(res.data[0][info], function(cr) {
				temp.rate.push(cr.rate);
				temp.echartsX.push(cr.time);
			});

			var option = {
				title: {
					text: title,
					x: 'center'
				},
				animation: false,
				grid: {
					x2: 100
				},
				tooltip: {
					show: true
				},
				xAxis: [{
					type: 'category',
					axisLabel: {
						show: false
					},
					data: temp.echartsX
				}],
				yAxis: [{
					type: 'value',
					name: yName
				}],
				series: [{
					type: 'line',
					data: temp.rate
				}]
			};
			return option;
		}
	}
})();